<?php
/**
  *@function 得到所有的分类信息
  *
  *@date 2013-05-29 20:17
  *
  */
class M_category extends CI_Model {
	
	protected $table_name = 'zy_category';

    function __construct()
    {
        parent::__construct();
		$this->load->database();
    }
    
    /**
     * 检索出分类
     * 
     * @param int $parent_id 父级的ID 默认为1
     * @param int $limit 分类需要检索的数目,如果为0,则检索出所有的
     */
    public function selectCategory($parent_id = 1 , $limit = 0)
    {
    	if(!$limit)
    	{
    		$this->db->order_by("cate_sort","DESC");
    		return $this->db->get_where( $this->table_name ,array('cate_parent'=>$parent_id,'cate_status'=>'1'))->result();
    	}
    	else
    	{
    		$this->db->order_by("cate_sort","asc");
    		return $this->db->get_where( $this->table_name ,array('cate_parent'=>$parent_id,'cate_status'=>'1'),$limit,'0')->result();
    	}
    	
    }
    
    /**
     * 根据分类的ID获取分类的名称
     */
    public function selectCategoryById($category_id)
    {
    	return $this->db->get_where( $this->table_name , array('cate_id' => $category_id))->result();
    }
    
    /**
     * 更具分类的条件检索分类的名称
     */
    /*public function selectCategoryByWhere($where)
    {
    	$query = "SELECT * FROM `zy_category` WHERE {}";
    }*/
	
	/**
     * 检索出父级分类ID下所有分类
     * 
     * @param int $parent_id 父级的ID 默认为0
     */
    public function selectCategoryByParentId($parent_id = 0)
    {
    	return $this->db->get_where( $this->table_name ,array('cate_parent'=>$parent_id,'cate_status'=>'1'))->result();
    }
    
    /**
     * 根据分类名称模糊匹配
     */
	public function searchCategoryByName($name)
    {
    	$this->db->like('cate_name',$name);
    	return $this->db->get( $this->table_name)->result();
    }
    
    
  

    
    

}